﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.ProcessManager.Server.Process.Security;
using Sinacor.Infra.Core.ProcessManager.Server.Security;
using Sinacor.Infra.Service.Common;
using Sinacor.Infra.Service.Security.Services;
using Sinacor.Process.Bovespa.Distribuicao.Server.Bovespa.Movimento.ControleMovimentoOrdens;

namespace Sinacor.Process.Bovespa.Distribuicao.Server.Communication
{
    public class ControleMovimentoOrdens : BaseCommunication 
	{
		#region Construtor

		public ControleMovimentoOrdens()
			: base(AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.LoginName, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.Password, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.CompanyId)
		{
		}

		#endregion

		#region Métodos

		public ProcessEntity.InformacoesMovimento ObterInformacoesMovimento()
		{
            IControleMovimentoOrdens servico = null;
            Translator.DataContractToProcessEntity.ControleMovimentoOrdens translatorResponse = null;
            ProcessEntity.InformacoesMovimento retorno = null;

            try
            {
                using (ServiceInstance<IControleMovimentoOrdens> service = new ServiceInstance<IControleMovimentoOrdens>())
                {
                    servico = service.TryGetInstance(this.LoginName, this.Password, this.CompanyId);
                    translatorResponse = new Translator.DataContractToProcessEntity.ControleMovimentoOrdens();
                    retorno = translatorResponse.ToInformacoesMovimento(servico.ObterInformacoesMovimento(new DataMovimentoRequest()));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return retorno;
		}

		#endregion
	}
}
